// 2025/10/15
// 快乐数

class Solution {
public:
    bool isHappy(int n) {
        unordered_set<int> isChecked = {n};
        while(n != 1)
        {
            int next = 0;
            while(n)
            {
                int tmp = n % 10;
                next += tmp * tmp;
                n /= 10;
            }
            if(isChecked.count(next))
            {
                return false;
            }
            isChecked.emplace(next);
            n = next;
        }
        return true;
    }
};